import org.apache.tools.ant.taskdefs.condition.Os

apply plugin: 'com.android.library'

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    sourceSets {
        main {
            java.srcDirs = ['../src/main/java']
            manifest.srcFile '../src/main/AndroidManifest.xml'
        }
    }

    defaultConfig {
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode rootProject.ext.versionCode
        versionName rootProject.ext.versionName

        externalNativeBuild {
            cmake {
                targets "image"
                arguments "-DANDROID_ARM_NEON=TRUE",
                          "-DIMAGE_SINGLE_SHARED_LIB=TRUE"
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), '../proguard-rules.pro'
        }
    }

    externalNativeBuild {
        cmake {
            path '../src/main/jni/CMakeLists.txt'
        }
    }
}

clean {
    delete '../src/main/jni/image/javah'
}

task javah(type: Exec, dependsOn: 'compileReleaseJavaWithJavac') {
    char separator = Os.isFamily(Os.FAMILY_WINDOWS) ? ';' : ':'
    commandLine 'javah', '-jni',
            '-d', '../src/main/jni/image/javah',
            '-cp', "${android.getSdkDirectory().getAbsolutePath()}/platforms/android-${rootProject.ext.targetSdkVersion}/android.jar${separator}build/intermediates/javac/release/compileReleaseJavaWithJavac/classes",
            'com.hippo.image.Image',
            'com.hippo.image.StaticImage',
            'com.hippo.image.StaticDelegateImage',
            'com.hippo.image.AnimatedImage',
            'com.hippo.image.AnimatedDelegateImage',
            'com.hippo.image.BitmapDecoder',
            'com.hippo.image.BitmapRegionDecoder'
    inputs.dir('../src/main/java')
    outputs.dir('../src/main/jni/image/javah')
}

dependencies {
    implementation "com.android.support:support-annotations:${rootProject.ext.supportLibraryVersion}"
    testImplementation "junit:junit:${rootProject.ext.junitVersion}"
}

project.afterEvaluate {
    externalNativeBuildDebug.dependsOn javah
    externalNativeBuildRelease.dependsOn javah
}

// Publish arr with java source and java doc
apply from: rootProject.file('android-maven-gradle.gradle')
